#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author: wangxiaoming 2021-11-16
# desc: thermal测试类

import enum
import unittest
import os
import time
import struct
from ctypes import *
from mainunit_common import *
from mainunit_api import *

class testself_acc_drv(unittest.TestCase):
    g_acc_val=-1
    
    def data_callback(self, data):
        print(f'\tdata={data}')
        self.g_acc_val = data
        
    def error_callback(self, err):
        print(f'\terr={err}')
        
    def testself1_acc_drv_on(self):
        print(f'\t==================================')
        expected=ECODE_OK
        
        ret = acc_drv_init()
        print(f'\tstep. call api: acc_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        txt = sp_input("\n\tPLEASE CHECK ACC LINE CONNECTED AND INPUT ANY KEY TO CONTINUE\n")
        
        status = c_int(-1)
        ret = acc_drv_get_status(pointer(status))        
        print(f'\tstep. call api: acc_drv_get_status, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
		
        self.assertEqual(1, status.value)
        
        ret = acc_drv_uinit()
        print(f'\tstep. call api: acc_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
		
        print('\t**********************************')

    def testself2_acc_drv_off(self):
        print(f'\t==================================')
        expected=ECODE_OK
        
        ret = acc_drv_init()
        print(f'\tstep. call api: acc_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        txt = sp_input("\n\tPLEASE PICK OFF ACC LINE AND INPUT ANY KEY TO CONTINUE\n")
        
        time.sleep(5)
        
        status = c_int(-1)
        ret = acc_drv_get_status(pointer(status))        
        print(f'\tstep. call api: acc_drv_get_status, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
		
        self.assertEqual(0, status.value)
        
        ret = acc_drv_uinit()
        print(f'\tstep. call api: acc_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
		
        print('\t**********************************')
        
    def testself3_acc_drv_start(self):
        print(f'\t==================================')
        expected=ECODE_OK
        erro_cb_obj = ErrorCallBack(self.error_callback)
        data_cb_obj = ErrorCallBack(self.data_callback)
        
        
        ret = acc_drv_init()
        print(f'\tstep. call api: acc_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)        
        
        ret = acc_drv_start(data_cb_obj,erro_cb_obj)
        print(f'\tstep. call api: acc_drv_start, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
        
        txt = sp_input("\n\tPLEASE CONNECT and PICK OFF ACC LINE AND INPUT ANY KEY TO CONTINUE\n")
        time.sleep(5)
        self.assertEqual(0, self.g_acc_val)
        
        txt = sp_input("\n\tPLEASE CONNECT ACC LINE AND INPUT ANY KEY TO CONTINUE\n")
        time.sleep(1)
        self.assertEqual(1, self.g_acc_val)
        
        ret = acc_drv_stop()
        print(f'\tstep. call api: acc_drv_stop, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
		
        ret = acc_drv_uinit()
        print(f'\tstep. call api: acc_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
		
        print('\t**********************************')

    